<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * DISPENDA2BPD WEBSERVICE
 *
 * An close source application development
 *
 * @package		DISPENDA GIANYAR WEBSERVICE
 * @author		Andi Kurniawan
 * @copyright           PT. RUMAH LINUX YOGYAKARTA (c) 2013.
 * @license		nakamichikun@gmail.com
 * @follow		@nakamichikun
 * @since		Version 1.0
 * @filesource
 */
class Modsvc extends CI_Model {

    function testdb() {
        $data = $this->db->query("SELECT * FROM BPHTB");
        return $data->result();
    }

    function svcData() {
        $data = $this->db->query("
                SELECT *
                FROM SPPT
                WHERE KD_PROPINSI||
                        KD_DATI2||
                        KD_KECAMATAN||
                        KD_KELURAHAN||
                        KD_BLOK||
                        NO_URUT||
                        KD_JNS_OP||
                        NM_WP_SPPT||
                        PBB_YG_HARUS_DIBAYAR_SPPT||
                        NPWP_SPPT||
                        JLN_WP_SPPT||
                        RT_WP_SPPT||
                        RW_WP_SPPT||
                        KELURAHAN_WP_SPPT||
                        KOTA_WP_SPPT||
                        THN_PAJAK_SPPT
                NOT IN
                        (SELECT KD_PROPINSI||
                                KD_DATI2||
                                KD_KECAMATAN||
                                KD_KELURAHAN||
                                KD_BLOK||
                                NO_URUT||
                                KD_JNS_OP||
                                NM_WP_SPPT||
                                PBB_YG_HARUS_DIBAYAR_SPPT||
                                NPWP_SPPT||
                                JLN_WP_SPPT||
                                RT_WP_SPPT||
                                RW_WP_SPPT||
                                KELURAHAN_WP_SPPT||
                                KOTA_WP_SPPT||
                                THN_PAJAK_SPPT
                        FROM SPPT_OLTP)
                AND STATUS_PEMBAYARAN_SPPT=0
                AND ROWNUM <=20"
        );
        return $data->result();
    }

    function nop() {
        $data = $this->db->query("
                SELECT KD_PROPINSI||
                        KD_DATI2||
                        KD_KECAMATAN||
                        KD_KELURAHAN||
                        KD_BLOK||
                        NO_URUT||
                        KD_JNS_OP
                FROM SPPT
                WHERE ROWNUM <=20"
        );
//                AND STATUS_PEMBAYARAN_SPPT=0
        return $data->result();
    }

    function chk() {
        $data = $this->db->query("SELECT KD_PROPINSI||
                                KD_DATI2||
                                KD_KECAMATAN||
                                KD_KELURAHAN||
                                KD_BLOK||
                                NO_URUT||
                                KD_JNS_OP AS NOP,
                                THN_PAJAK_SPPT
                        FROM SPPT_OLTP");
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function logEcho($param, $encSts) {
        $this->db->query("INSERT INTO LOG_WS(USERNAME,ACTION_FROM,ACTION,DATA,TIME,RETURN) VALUES(USER,'" . $this->input->ip_address() . "','ECHO_TEST','" . $param . "','" . gmdate('d-m-Y h:i:s') . "','" . $encSts . "')");
    }

    function logIns($param, $encSts) {
        $this->db->query("INSERT INTO LOG_WS(USERNAME,ACTION_FROM,ACTION,DATA,TIME,RETURN) VALUES(USER,'" . $this->input->ip_address() . "','TAGIHAN INSERT','" . $param . "','" . gmdate('d-m-Y h:i:s') . "','" . $encSts . "')");
    }

    function logDelIns($param, $return) {
        $this->db->query("INSERT INTO LOG_WS(USERNAME,ACTION_FROM,ACTION,DATA,TIME,RETURN) VALUES(USER,'" . $this->input->ip_address() . "','DELETE INSTANSI','" . $param . "','" . gmdate('d-m-Y h:i:s') . "','" . $return . "')");
    }

    function logRptPay($param) {
        $this->db->query("INSERT INTO LOG_WS(USERNAME,ACTION_FROM,ACTION,DATA,TIME) VALUES(USER,'" . $this->input->ip_address() . "','REPORT PAYMENT DETAIL','" . $param . "','" . gmdate('d-m-Y h:i:s') . "')");
    }

    function svcSend($no, $thn) {
        $this->db->query("UPDATE SPPT_oltp SET SEND='1' WHERE NO_URUT='" . $no . "' AND THN_PAJAK_SPPT='" . $thn . "'");
    }

    function reportPayment($param) {
        $this->db->query($param);
    }

    function hitung() {
        $data = $this->db->query("SELECT * FROM (SELECT * FROM SPPT_oltp WHERE STATUS_PEMBAYARAN_SPPT=0) WHERE ROWNUM <= 10");
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function insSpptKirim($params) {
        $this->db->query("INSERT INTO BPHTB_HISTORY(ID,NAMA,JUMLAH_PAJAK,INSTANSI,NOP) VALUES(" . $params->id
                . ",'" . $params->nama
                . "'," . $params->jumlah
                . ",'" . $params->instansi .
                "','" . $params->nop . "')");
    }

    function umum($params) {
        $this->db->query($params);
    }

    function chkTrxBank($id, $sts_reversal) {
        $data = $this->db->query("SELECT * FROM TRANSAKSI_BANK WHERE ID=" . $id . "AND STS_REVERSAL=" . $sts_reversal);
        if ($data->num_rows > 0) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateSppt($nop, $tahun) {
        $this->db->query("UPDATE sppt SET status_pembayaran_sppt=1 WHERE kd_propinsi||kd_dati2||kd_kecamatan||kd_kelurahan||kd_blok||no_urut||kd_jns_op=" . $nop . " AND thn_pajak_sppt=" . $tahun . "");
    }

    function updateSpptReversal($nop, $tahun) {
        $this->db->query("UPDATE sppt SET status_pembayaran_sppt=0 WHERE kd_propinsi||kd_dati2||kd_kecamatan||kd_kelurahan||kd_blok||no_urut||kd_jns_op=" . $nop . " AND thn_pajak_sppt=" . $tahun . "");
    }

}

?>
